package com.pajk.commons.types;

import java.io.Serializable;

/**
 * Wrapper class to hold versioned value of given type
 *
 * @author Sean Gao
 */
public class VersionedValue<T> implements Serializable {

    private Long version = 0L;
    private T value;

    public Long getVersion() {
        return version;
    }

    public T getValue() {
        return value;
    }

    public VersionedValue(Long version, T value) {
        this.version = version;
        this.value = value;

    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        VersionedValue that = (VersionedValue) o;

        if (!value.equals(that.value)) return false;
        if (!version.equals(that.version)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = version.hashCode();
        result = 31 * result + value.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "VersionedValue{" +
                "version=" + version +
                ", value=" + value +
                '}';
    }
}